// import {EventEmitter as emitter} from "node/events";

var superagent = require('superagent')
require('superagent-charset')(superagent) // install charset
const cheerio=require('cheerio');
const reptileUrl="https://www.douban.com/doumail/";


// getPhoneNumber();
login();

function getPage(cookie) {
  superagent
  .get('https://movie.douban.com/top250')
  // .http2()
  // .set('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3')
  // .set('Accept-Encoding','gzip, deflate, br')
  // .set('Accept-Language','zh-CN,zh;q=0.9')
  // .set('Cache-Control','max-age=0')
  // .set('Connection','keep-alive')
  .set('Cookie',cookie)
  // .set('Host','movie.douban.com')
  // .set('Upgrade-Insecure-Requests',1)
  .set('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36')
  // .charset('gbk')
  .end(function (err, resp) {
    if(err){
      console.log(err);
      return;
    }
    // emitter.emit()
    console.log(resp.text);
  })
}



function getPhoneNumber() {
  superagent
  .post('https://accounts.douban.com/j/mobile/login/request_phone_code')
  .send({
    "ck":null,'area_code': '+86','number': '13602153871'
  })
  .set('Accept','application/json')
  .set('Content-Type','application/x-www-form-urlencoded')
  .set('Origin','https://accounts.douban.com')
  .set('Referer','https://accounts.douban.com/passport/login_popup?login_source=anony')
  .set(
    'User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
  )
  .set('X-Requested-With','XMLHttpRequest')
  .end(function (err, resp) {
    if(err){
      console.log(err);
      return;
    }

    console.log(resp.text);

  })
}


function login() {

  superagent
    .post('https://accounts.douban.com/j/mobile/login/verify_phone_code')
    .send({
      "ck":null
      ,'area_code': '+86'
      ,'number': '13602154870'
      ,'code':7833
      ,'remember':false
      ,'ticket':null
    })
    .set('Accept','application/json')
    .set('Content-Type','application/x-www-form-urlencoded')
    .set('Origin','https://accounts.douban.com')
    .set('Referer','https://accounts.douban.com/passport/login?source=main')
    .set(
      'User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
    )
    .set('X-Requested-With','XMLHttpRequest')
    .end(function (err, resp) {
      if(err){
        console.log(err);
        return;
      }
      console.log(resp.headers['set-cookie'][0]);
      getPage(resp.headers['set-cookie'][0])
      // console.log();

    })
}
